package com.igeek.boot.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeek.boot.anno.WMSLoganno;
import com.igeek.boot.entity.Outgoingstock;
import com.igeek.boot.result.Result;
import com.igeek.boot.service.IOutgoingstockService;
import com.igeek.boot.vo.PageQueryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jwj
 * @since 2023-12-26
 */
@RestController
@RequestMapping("/wisdom_factory/outgoingstock")
@Api(tags = "出库表接口")
public class OutgoingstockController {

    @Autowired
    private IOutgoingstockService outgoingstockService;

    //分页查询出库订单
    @ApiOperation("条件分页查询出库订单")
    @GetMapping ("/findPage")
    public Result findPage(@ApiParam("分页条件") PageQueryVO pageQueryVO){
        //查询出库订单
        Page<Outgoingstock> page = outgoingstockService.findPage(pageQueryVO);
        return new Result(true,"查询成功",page);
    }

    //修改出库订单信息
    @ApiOperation("修改出库订单")
    @PutMapping("/updateOutgoingStockInfo")
    public Result updateOutgoingStockInfo(@ApiParam("出库订单信息") @RequestBody Outgoingstock outgoingstock){
        //修改出库订单信息
        boolean flag = outgoingstockService.updateById(outgoingstock);
        if(flag){
            return new Result(true,"修改成功");
        }
        return new Result(true,"修改失败");
    }

    //确认修改出库订单
    @WMSLoganno(module = "出库订单",operation = "修改出库信息")
    @ApiOperation("确认修改出库订单")
    @PostMapping("/confirmUpdateOutgoingStock")
    public Result confirmUpdateOutgoingStock(@ApiParam("出库订单信息") @RequestBody Outgoingstock outgoingstock,
                                             @ApiParam("出库的物资id") @RequestParam("assetID") Integer assetID){
        //确认修改出库订单
        boolean flag = outgoingstockService.confirmUpdateOutgoingStock(outgoingstock,assetID);
        if(flag){
            return new Result(true,"修改成功");
        }
        return new Result(true,"修改失败");
    }

    //添加出库订单信息
    @WMSLoganno(module = "出库订单",operation = "添加出库信息")
    @ApiOperation("添加出库订单信息")
    @PostMapping("/addOutgoingStockInfo")
    public Result addOutgoingStockInfo(@ApiParam("出库订单信息") @RequestBody Outgoingstock outgoingstock,
                                       @ApiParam("出库的物资id") @RequestParam("assetID") Integer assetID){
        //添加出库订单信息
        boolean flag = outgoingstockService.addOutgoingStockInfo(outgoingstock,assetID);
        if(flag){
            return new Result(true,"添加成功");
        }
        return new Result(true,"添加失败");
    }

    //确认出库操作
    @WMSLoganno(module = "出库订单",operation = "进行出库操作")
    @ApiOperation("确认出库操作")
    @PostMapping("/confirmOutgoingStock")
    public Result confirmOutgoingStock(@ApiParam("出库订单信息") @RequestBody Outgoingstock outgoingstock){
        //确认出库操作
        boolean flag = outgoingstockService.confirmOutgoingStock(outgoingstock);
        if(flag){
            return new Result(true,"出库成功");
        }
        return new Result(false,"出库失败，当前库存不足，等待管理员补货");
    }

    //删除出库订单的信息
    @WMSLoganno(module = "出库订单",operation = "删除出库订单")
    @ApiOperation("删除出库订单的信息")
    @DeleteMapping("/delOutgoingStock/{id}")
    public Result delOutgoingStock(@PathVariable("id") Integer id){
        //删除出库订单的信息
        boolean flag = outgoingstockService.removeById(id);
        if(flag){
            return new Result(true,"删除成功");
        }
        return new Result(true,"删除失败");
    }
}
